/*
 * serial.h
 *
 *  Created on: 2012-07-11
 *      Author: wojciech
 */

#ifndef SERIAL_H_
#define SERIAL_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Constant to access the VIC. */
#define serCLEAR_VIC_INTERRUPT			( ( unsigned long ) 0 )

/* Constants to determine the ISR source. */
#define serSOURCE_THRE					( ( unsigned char ) 0x02 )
#define serSOURCE_RX_TIMEOUT			( ( unsigned char ) 0x0c )
#define serSOURCE_ERROR					( ( unsigned char ) 0x06 )
#define serSOURCE_RX					( ( unsigned char ) 0x04 )
#define serINTERRUPT_SOURCE_MASK		( ( unsigned char ) 0x0f )

/* Constants to setup and access the UART. */
#define serDLAB							( ( unsigned char ) 0x80 )
#define serENABLE_INTERRUPTS			( ( unsigned char ) 0x03 )
#define serNO_PARITY					( ( unsigned char ) 0x00 )
#define ser1_STOP_BIT					( ( unsigned char ) 0x00 )
#define ser8_BIT_CHARS					( ( unsigned char ) 0x03 )
#define serFIFO_ON						( ( unsigned char ) 0x01 )
#define serCLEAR_FIFO					( ( unsigned char ) 0x06 )
#define serWANTED_CLOCK_SCALING			( ( unsigned long ) 16 )

#define UART0		0
#define UART1		1
#define UART2		2
#define UART3		3
#define UART4		4

void vSerialInit(int pxPort, uint32_t baud);
void vSerialRebaud(int pxPort, uint32_t baud);
int xSerialGetChar( int pxPort, unsigned char *pcRxedChar, unsigned int xBlockTime );
int xSerialPutChar( int pxPort, unsigned char cOutChar, unsigned int xBlockTime );
int xSerialPutString( int pxPort, const char * pcString, unsigned short usStringLength );
int xSerialPutData( int pxPort, unsigned char * pucData, unsigned short usDataLength );

#ifdef __cplusplus
}
#endif

#endif /* SERIAL_H_ */
